package com.sctvcloud.dongqu.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.ruihang.generalibrary.ui.dialog.BaseDialogFragment;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.dongqu.R;

public class ChooseCityFuncFragment extends BaseDialogFragment implements View.OnClickListener {
    private CustomFontTextView titleTxt;
    private CustomFontTextView messageTxt;
    private CustomFontTextView messageTxtT;
    private CheckBox notRemind;
    private CustomFontTextView btnCancel;
    private CustomFontTextView btnOk;
    public static final int NO_TAG = 101;
    public static final int OK_TAG = 202;
    private String title;
    private String message;
    private String noTxt;
    private String okTxt;
    private boolean isSelected = false;
    private boolean isShowRemind = true;

    public ChooseCityFuncFragment() {

    }

    @Override
    protected int getContentRes() {
        return R.layout.dia_choose_city_func;
    }

    @Override
    protected void initViews(Dialog dialog, Bundle savedInstanceState) {
        titleTxt = (CustomFontTextView) dialog.findViewById(R.id.title);
        messageTxt = (CustomFontTextView) dialog.findViewById(R.id.message_txt);
        messageTxtT = (CustomFontTextView) dialog.findViewById(R.id.message_txt_t);
        notRemind = (CheckBox) dialog.findViewById(R.id.not_remind);
        notRemind.setChecked(false);
        btnCancel = (CustomFontTextView) dialog.findViewById(R.id.btn_cancel);
        btnOk = (CustomFontTextView) dialog.findViewById(R.id.btn_ok);
        btnOk.setText("切换");
        btnCancel.setText("暂不切换");
        btnCancel.setOnClickListener(this);
        btnOk.setOnClickListener(this);
        if (TextUtils.isEmpty(title)) {
            titleTxt.setVisibility(View.GONE);
        } else {
            titleTxt.setVisibility(View.VISIBLE);
            titleTxt.setText(title);
        }
        if (TextUtils.isEmpty(message)) {
            messageTxt.setVisibility(View.GONE);
        } else {
            messageTxt.setVisibility(View.VISIBLE);
            messageTxt.setText(message);
        }
        if (!TextUtils.isEmpty(noTxt)) {
            btnCancel.setText(noTxt);
        }
        if (!TextUtils.isEmpty(okTxt)) {
            btnOk.setText(okTxt);
        }
        if (!isShowRemind) {
            notRemind.setVisibility(View.GONE);
        }
//        messageTxtT.setText("点击顶部位置可自由切换");
        notRemind.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isSelected = isChecked;
            }
        });
    }

    /**
     * 设置提示框文字
     *
     * @param title
     * @param message
     */
    public void setDialogText(String title, String message) {
        if (null != titleTxt && null != messageTxt) {
            if (TextUtils.isEmpty(title)) {
                titleTxt.setVisibility(View.GONE);
            } else {
                titleTxt.setVisibility(View.VISIBLE);
                titleTxt.setText(title);
            }
            if (TextUtils.isEmpty(message)) {
                messageTxt.setVisibility(View.GONE);
            } else {
                messageTxt.setVisibility(View.VISIBLE);
                messageTxt.setText(message);
            }
        } else {
            this.title = title;
            this.message = message;
        }
    }

    public void setDialogBtnText(String noTxt, String okTxt) {
        if (null != btnCancel && null != btnOk) {
            if (TextUtils.isEmpty(noTxt)) {
                btnCancel.setVisibility(View.GONE);
            } else {
                btnCancel.setVisibility(View.VISIBLE);
                btnCancel.setText(noTxt);
            }
            if (TextUtils.isEmpty(okTxt)) {
                btnOk.setVisibility(View.GONE);
            } else {
                btnOk.setVisibility(View.VISIBLE);
                btnOk.setText(okTxt);
            }
        } else {
            this.noTxt = noTxt;
            this.okTxt = okTxt;
        }
    }

    public void setDialogNotShowRemind() {
        isShowRemind = false;
        if (null != notRemind) {
            notRemind.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        Message message = new Message();
        if (v == btnCancel) {
            if (callBack != null) {
                message.what = NO_TAG;
                message.obj = isSelected;
                callBack.onCallBackMsg(this, message);
            }
        } else if (v == btnOk) {
            if (callBack != null) {
                message.what = OK_TAG;
                message.obj = isSelected;
                callBack.onCallBackMsg(this, message);
            }
        }
        dismissAllowingStateLoss();

    }
}
